<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const goods = [
        { uname: '小米', price: 5000 },

        { uname: '苹果', price: 1000 },

        { uname: '华为', price: 10000 },

        { uname: 'oppo', price: 6000 },

        { uname: 'vivo', price: 7000 },

        { uname: '红米', price: 3000 },

        { uname: '诺基亚', price: 8000 },
      ]
      // 要求1 找到小米这个对象 返回回来把品牌和价格显示在页面当中
      for (let i = 0; i < goods.length; i++) {
        if (goods[i].uname === '小米') {
          document.write(`品牌：${goods[i].uname}，价格：${goods[i].price}`)
        }
      }

      // 要求2 买这里面最贵的 告诉用户哪个品牌多少钱（把价格放数组中）
      let max = [goods[0]]
      for (let i = 0; i < goods.length; i++) {
        if(max[0].price < goods[i].price){
          max[0] = goods[i]
        }
        }
        console.log(max);
        document.write(`<br>最贵的品牌是${max[0].uname},价格为${max[0].price}`)


      // 要求3 判断这里面的价格大于3000的汇总（ { uname: '小米', price: 3000 }） 排序（降序）
      let goods2 = []
      for (let i = 0; i < goods.length; i++) {
        if (goods[i].price > 3000) {
          goods2.push(goods[i])
        }
      }
      // 冒泡排序
      for (let i = 0; i < goods2.length; i++) {
        for (let j = i; j <= goods2.length - 1; j++) {
          if (goods2[i].price > goods2[j].price) {
            let temp = goods2[i]
            goods2[i] = goods2[j]
            goods2[j] = temp
          }
        }
      }
      console.log(goods2)
    </script>
  </body>
</html>
